<html>
  <head>
    <script>
    // Click on a link by id to star a test case.
    function clickLink(linkId) {
      var node = document.getElementById(linkId);
      if (node != null) {
        // Click and open link in the same tab.
        node.click();
      }
    }

    // Redirect via window.location.
    function windowLocationRedirection() {
      window.location.assign("../signed.exe");
    }

    function mixRedirectDownload() {
      window.location.assign("redirect.html");
    }

    // This triggers a download in a new tab with no opener.
    function downloadInNewTab() {
      var tab = window.open('');
      tab.opener = null;
      tab.document.write('<META HTTP-EQUIV="refresh" content="0; url=../signed.exe">');
      tab.document.close();
    }

    // Trigger download in a new tab and the download is from a data url.
    function downloadInNewTabWithDataURL() {
       var tab = window.open('');
       tab.opener = null;
       tab.document.write('<META HTTP-EQUIV="refresh" content="0; url=data:application/octet-stream;base64,a2poYWxrc2hkbGtoYXNka2xoYXNsa2RoYWxraGtoYWxza2hka2xzamFoZGxramhhc2xka2hhc2xrZGgKYXNrZGpoa2FzZGpoYWtzaGRrYXNoZGtoYXNrZGhhc2tkaGthc2hka2Foc2RraGFrc2hka2FzaGRraGFzCmFza2pkaGFrc2hkbSxjbmtzamFoZGtoYXNrZGhhc2tka2hrYXNkCjg3MzQ2ODEyNzQ2OGtqc2hka2FoZHNrZGhraApha3NqZGthc2Roa3NkaGthc2hka2FzaGtkaAohISomXkAqJl4qYWhpZGFzeWRpeWlhc1xcb1wKa2Fqc2Roa2FzaGRrYXNoZGsKYWtzamRoc2tkaAplbmQK">');
       tab.document.close();
    }

    // Create a data blob and save it as a test.exe file in filesystem's
    // space with use URL filesystem:http://test_host/temporary/test.exe
    // to download it.
    function downloadViaFileApi(){
      var errorize = function(e){console.log(e);};
      var filename = 'test.exe';
      var blob = new Blob([new Uint8Array([1, 2, 3, 4])],{type:'application/octet-stream'});
      window.webkitRequestFileSystem(
        window.TEMPORARY,1048576,
        function(fs){
          var createFile = function(){
            fs.root.getFile(
              filename,
              {create:true, exclusive:true},
              function(fileEntry){
                fileEntry.createWriter(
                  function(writer){
                    writer.onwriteend = function(){
                      var save_link = document.createElementNS("http://www.w3.org/1999/xhtml", "a");
                      save_link.href = fileEntry.toURL();
                      save_link.download = filename;
                      var event = new MouseEvent("click");
                      save_link.dispatchEvent(event);
                    };
                    writer.onerror = errorize;
                    writer.write(blob);
                  },
                  errorize);
              },
              errorize);
          };
          fs.root.getFile(
            filename,{create:false},
            function(fileEntry){
              fileEntry.remove(createFile,errorize);
            },
            createFile);
          },
          errorize);
    }
    </script>
  </head>
  <body>
    <a id="direct_download" href="../signed.exe">
      Direct download
    </a><br>

    <a id="direct_download_noreferrer" href="../signed.exe" rel="noreferrer">
      Direct download noreferrer
    </a><br>

    <a id="direct_download_noreferrer_target_blank" href="../signed.exe" rel="noreferrer" target=_blank>
      Direct download noreferrer target blank
    </a><br>

    <a id="single_meta_refresh_redirect" href="redirect.html">
      Redirect download via meta refresh
    </a><br>

    <a id="single_meta_refresh_redirect_target_blank" href="redirect.html" target=_blank>
      Redirect download via meta refresh target blank
    </a><br>

    <a id="multiple_meta_refresh_redirects" href="double_redirect.html">
      Redirect download multiple times via meta refresh
    </a><br>

    <a id="window_location_redirection" href="#" onclick="windowLocationRedirection(); return false;">
      Redirect via window.location
    </a><br>

    <a id="mix_redirects" href="#" onclick="mixRedirectDownload(); return false;">
      Redirect download via mix of window.location.href and meta refresh
    </a><br>

    <a id="new_tab_download" href="#" onclick="downloadInNewTab(); return false;">
      Open download in new tab
    </a><br>

    <a id="new_tab_download_with_data_url" href="#" onclick="downloadInNewTabWithDataURL(); return false;">
      Open download in new tab with data url
    </a><br>

    <a id="new_tab_download_with_server_redirect" href="#" rel="noreferrer" target=_blank>
      Open navigation in a new tab and immediately redirect to a download by server.
    </a><br>

    <script>
      var request = location.origin + "/server-redirect?" + location.origin +
                    "/safe_browsing/download_protection/signed.exe";
      document.getElementById("new_tab_download_with_server_redirect")
              .setAttribute('href', request);
    </script>

    <a id="sub_frame_download_attribution" href="navigation_observer_multi_frame_tests.html">
      Download in subframe.
    </a><br>

    <a id="complete_referrer_chain" href="redirect_to_landing.html">
      Click on landing referrer and landing page then reach download
    </a><br>

    <a id="attribution_within_two_user_gestures" href="page_before_landing_referrer.html">
      Attribution should not trace back more than 2 user gestures.
    </a><br>

    <button id="html5_file_api" onclick="downloadViaFileApi()">
      Download via HTML5 file system API without trigger navigation
    </button><br>

    <a id="attribution_should_ignore_url_fragments" href="page_before_landing_referrer.html">
      Attribution should ignore url fragments.
    </a><br>

  </body>
</html>
